package com.yq.leetcodeOld;

/**
 * @ClassName ThreadLocalTest
 * @Description TODO
 * @Author yaoqiang
 * @Date 2022/3/21 10:03
 * @Version 1.0
 */
public class ThreadLocalTest {
    static ThreadLocal<String> localVal= new ThreadLocal<>();
    static void print(String str){
        System.out.println(str+":"+localVal.get());
        localVal.remove();
    }
    public static void main(String[] args) {
        Thread t1= new Thread(new Runnable() {
            @Override
            public void run() {
                localVal.set("localvar1");
                print("thread1");
                System.out.println("after remove"+localVal.get());
            }
        });
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                localVal.set("localvar2");
                print("thread2");
                System.out.println("after remove"+localVal.get());
            }
        });
        t1.start();
        t2.start();
    }
}
